<?php
class Zendvn_Model_Table_SiteConfig extends Zend_Db_Table{
	protected $_name = "site_config";
	protected $_primary = "id"; 
	protected $_arrParam = array();


	public function getItem($arrParam = null,$options = null){
		if($options == null){
			$where = 'id = ' . (int)$arrParam['id'];
			$result = $this->fetchRow($where);
			if(!empty($result))
				$result = $result->toArray();
		}
		return $result;
	}

	public function listItem($arrParam = null,$options = null){
		if($options == null){
			$db = $this->getAdapter();
			$select = $db->select()
						 ->from($this->_name);						 

			$arrFilter = $arrParam['arrFilter'];
			if(!empty($arrFilter['col'])){
				$select->order($arrFilter['col'] . ' ' . $arrFilter['order']);			
			}
			if(!empty($arrFilter['status']) && $arrFilter['status'] != 'none'){
				$select->where('status = ?',$arrFilter['status']);
			}
			if(!empty($arrFilter['keyword']) && !empty($arrFilter['searchField'])){
				$keyword = '%' . $arrFilter['keyword'] . '%';
				$select->where($arrFilter['searchField'] . ' LIKE ? ', $keyword);
			}
			if($arrParam['action'] == 'edit'){
				$select->where('id != ' . $arrParam['id']);	
			}
			$this->_listSQL = $select;			
			$result = $db->fetchAll($select);
		}
		return $result;
	}
	
	public function saveItem($arrParam = null,$options = null){
		$function  = Zendvn_System_Function::call($options['task']);
		$this->$function($arrParam);
	}


	public function adminEdit($arrParam = null){
		$str = new Zendvn_Filter_Filter();
		$where = 'id = ' . (int)$arrParam['id'];
		
		
		$row = $this->fetchRow($where);	
		$row->site_name			= $arrParam['site_name'];
		$row->logo				= $arrParam['logo'];
		$row->html_keyword		= $arrParam['html_keyword'];
		$row->html_description	= $arrParam['html_description'];
		
		$row->yahoo				= $arrParam['yahoo'];
		$row->skype				= $arrParam['skype'];
		$row->phone				= $arrParam['phone'];
		
		$row->mail_server		= $arrParam['mail_server'];
		$row->mail_send			= $arrParam['mail_send'];
		$row->mail_password		= $arrParam['mail_password'];
		$row->mail_title		= $arrParam['mail_title'];
		$row->mail_receive		= $arrParam['mail_receive'];
		
		$row->footer_content	= $arrParam['footer_content'];
		$row->save();
	}

}